import functools
class Solution(object):
    def minDeletion(self, nums):
        n = len(nums)
        @functools.cache
        def dfs(i):
            if n - i <= 1:
                return n - i
            else:
                j = i + 1
                while j < n and nums[j] == nums[i]:
                    j += 1
                if j == n:
                    return 1
                else:
                    return max(2 + dfs(j + 1), dfs(j))
        m = dfs(0)
        if m % 2 == 1:
            return n - m - 1
        else:
            return n - m

data = Solution()
nums = [1,1,2,2,3,3]
print(data.minDeletion(nums))